var lcff_promptSave_options = {
    fields : [],
    onLoad : function() {
        lcff_promptSave_options.fields = window.arguments[0].fieldsin;
        var container = document.getElementById("field-container");
        for(var i=0;i<lcff_promptSave_options.fields.length;i++) {
            var thisField = lcff_promptSave_options.fields[i];
            var row = document.createElement('row');
            var checkbox = document.createElement('checkbox');
            checkbox.setAttribute('id', 'chk'+ thisField.name);
            checkbox.setAttribute('checked', thisField.include);
            row.appendChild(checkbox);
            var txtFieldName = document.createElement('textbox');
            txtFieldName.setAttribute('id', 'txtName'+ thisField.name);
            txtFieldName.setAttribute('value', thisField.name);
            row.appendChild(txtFieldName);
            var txtFieldValue = document.createElement('textbox');
            txtFieldValue.setAttribute('id', 'txtVal'+ thisField.name);
            txtFieldValue.setAttribute('value', thisField.value);
            row.appendChild(txtFieldValue);
            container.appendChild(row);
        }
    },
    saveFieldsOptions : function() {
        var container = document.getElementById("fieldgrid");
        var rows = container.getElementsByTagName("rows")[0];
        var fieldsIncluded = [];
        var newFieldsAry = [];
//dump(rows.length+"\n");
        for(var i=1;i<rows.childNodes.length;i++) { // skip the first row, it contains the headers
            var row = rows.childNodes[i];
            var chkInclude = row.getElementsByTagName('checkbox')[0];
            var origName = chkInclude.id.substring(3);
            var inputs = row.getElementsByTagName('textbox');
            var fieldName, fieldVal;
            for(var j=0;j<inputs.length;j++) {
                switch(inputs[j].id) {
                    case "txtName"+origName:
                        fieldName = decodeURIComponent(inputs[j].value);
                        break;
                    case "txtVal"+origName:
                        fieldVal = decodeURIComponent(inputs[j].value);
                        break;
                }
            }
            if(typeof fieldsIncluded[fieldName] == 'undefined') {
                fieldsIncluded[fieldName] = 1;
                newFieldsAry[newFieldsAry.length] = {
                    name : fieldName,
                    value : fieldVal,
                    include : chkInclude.checked
                };
            }
        }
        if(newFieldsAry.length > 0) {
            window.arguments[0].fieldsout = newFieldsAry;
            close();
        } else {
            alert(LockCrypt.getString('err_NoFields'));
        }
    }
};